#ifndef _CRT_LOG_H_
#define _CRT_LOG_H_

#include <crt_core.hpp>

#ifdef __cplusplus
extern "C" {
#endif

#define log_error_tag   "error-tag:"
#define log_warning_tag "warning-tag:"
#define log_info_tag    "info-tag:"
#define log_debug_tag   "debug-tag:"

typedef enum sys_LogPriority {

    SYS_LOG_UNKNOWN = 0,
    SYS_LOG_DEFAULT, /* only for SetMinPriority() */
    SYS_LOG_VERBOSE,
    SYS_LOG_DEBUG,
    SYS_LOG_INFO,
    SYS_LOG_WARN,
    SYS_LOG_ERROR,
    SYS_LOG_FATAL,
    SYS_LOG_SILENT, /* only for SetMinPriority(); must be last */

} sys_LogPriority;

int log_print(int proi, const char* tag, int line, const char* func, const char* fmt, ...);

#if (TARGET_OS == OS_WIN)

#define _LOG_FUNCTION_ __FUNCTION__

#elif (TARGET_OS == OS_POSIX)

#define _LOG_FUNCTION_ __PRETTY_FUNCTION__

#elif (TARGET_OS == OS_MACH)

#define _LOG_FUNCTION_ __PRETTY_FUNCTION__

#elif (TARGET_OS == OS_UNIX)

#define _LOG_FUNCTION_ __PRETTY_FUNCTION__

#endif

#define loge(...) log_print(SYS_LOG_ERROR, log_error_tag, __LINE__, _LOG_FUNCTION_, __VA_ARGS__)
#define logw(...) log_print(SYS_LOG_WARN, log_warning_tag, __LINE__, _LOG_FUNCTION_, __VA_ARGS__)
#define logi(...) log_print(SYS_LOG_INFO, log_info_tag, __LINE__, _LOG_FUNCTION_, __VA_ARGS__)
#define logd(...) log_print(SYS_LOG_DEBUG, log_debug_tag, __LINE__, _LOG_FUNCTION_, __VA_ARGS__)

#ifdef __cplusplus
}
#endif

#endif
